package jam;

import jam.test.RobotTestBed;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import static org.junit.Assert.assertTrue;

/**
 * A behavioral test to make sure RunScared has an initial bodyHeading of 0.0, facing the north
 * wall.
 * 
 * @author John Mack
 * 
 */
public class TestFindHeading extends RobotTestBed {
  boolean verifyHeading = false;

  /**
   * Specifies that SittingDuck and RunScared are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Crazy,jam.RunScared";
  }

  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * On each turn ended, check to make sure the robot's bodyHeading is 0.0.
   * 
   * @param event Information about the battle.
   */

  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    checkHeading(robot);
  }

  /**
   * sets boolean verifyHeading to true if the robot bodyHeading is 0.0.
   * 
   * @param robot information about the robot at snapshot instance.
   */
  public void checkHeading(IRobotSnapshot robot) {
    if (robot.getBodyHeading() == 0.0) {
      verifyHeading = true;
    }

  }

  /**
   * Asserts that RunScared had initially as well as during the battle, faces its 
   * bodyHeading toward 0.0.
   * 
   * @param event information regarding completed battle.
   */

  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {

    assertTrue("RunScared faces 0.0", verifyHeading);

  }

}